package com.qidian.mes.service.impl;

import com.qidian.mes.mapper.RouteProductMapper;
import com.qidian.mes.pojo.RouteProduct;
import com.qidian.mes.service.RouteProductService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RouteProductServiceImpl implements RouteProductService {
    @Autowired
    private RouteProductMapper routeProductMapper;
    @Override
    public MESResult list(Long routeId) {
        return MESResult.ok(routeProductMapper.list(routeId));
    }

    @Override
    public MESResult delete(Long recordId) {
        routeProductMapper.deleteByRecordId(recordId);
        return MESResult.ok();
    }

    @Override
    public MESResult save(RouteProduct routeProduct) {
        routeProductMapper.sava(routeProduct);
        return MESResult.ok();
    }

    @Override
    public MESResult selectByRecordId(Long recordId) {
        RouteProduct routeProduct =null;
        if ((routeProduct=routeProductMapper.selectByRecordId(recordId)) !=null){
            return MESResult.ok(routeProduct);
        }
        return MESResult.empty();
    }

    @Override
    public MESResult update(RouteProduct routeProduct) {
        RouteProduct routeProduct1 = routeProductMapper.getByItemCode(routeProduct.getItemCode());
        if (routeProduct1 !=null && !routeProduct1.getItemCode().equals(routeProduct.getItemCode())){
            return MESResult.duplicate("产品物料编码重复");
        }
        routeProductMapper.update(routeProduct);
        return MESResult.ok();
    }
}
